package proxy.dynamicpro;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.*;

public class TeacherProxy {
    private Object target;

    public TeacherProxy(Object target) {
        this.target = target;
    }

    public Object getProxyInstance() {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("JDK 代理开始");
                        Object returnVal = method.invoke(target, args);
                        System.out.println("JDK 代理结束");
                        return returnVal;
                    }
                });
    }


}
